package com.algorithm;

import java.util.HashSet;
import java.util.Set;

/**
 * 存在重复元素
 */
public class ContainsDuplicate {

    public static boolean containsDuplicate(int[] nums) {
//        long count = Arrays.stream(nums).distinct().count();
//        return nums.length != count;
        Set<Integer> set=new HashSet<>();
        for (int num : nums) {
            if (set.contains(num)){
                return true;
            }
            set.add(num);
        }
        return false;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, 1, 1, 3, 3, 4, 3, 2, 4, 2};
        boolean result = containsDuplicate(nums);
        System.out.println(result);
    }
}
